package com.mlan.userap.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.mlan.userap.R;

public class VoiceDialog extends Dialog {
    private Context context;
    private String   msg;
    private TextView tvMsg;
    private ProgressBar bar_voice;
    private ImageView img_cancle;
    public VoiceDialog(Context context) {
        super(context, R.style.CustomerDialogTheme);
        this.context = context;
    }

    public void setMessage(String msg) {
        this.msg = msg;
        if (tvMsg != null && !TextUtils.isEmpty(msg)) {
            tvMsg.setText(msg);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
        setMessage("正在说话");
        setCancelable(false);
    }

    private void init() {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = View.inflate(context, R.layout.view_voice, null);
        setContentView(layout);

        tvMsg = layout.findViewById(R.id.tv_msg);
        bar_voice = layout.findViewById(R.id.progressbar_voice);
        img_cancle = layout.findViewById(R.id.voice_cancle);
        if (!TextUtils.isEmpty(msg)) {
            tvMsg.setText(msg);
        }
    }

    /**
     *
     * @param stype 1 正在说话  2 取消发送
     */
    public void showState(int stype) {
        if(stype==1){
            tvMsg.setText("正在说话");
            img_cancle.setVisibility(View.GONE);
            bar_voice.setVisibility(View.VISIBLE);
        }
        else{
            tvMsg.setText("取消发送");
            img_cancle.setVisibility(View.VISIBLE);
            bar_voice.setVisibility(View.GONE);
        }
    }
    @Override
    public void dismiss() {
        if (context != null && !((Activity) context).isFinishing()) {
            super.dismiss();
        }
    }
}
